#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn=5000, maxm=5000, inf=maxn*maxm+1;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

void swap(int &a, int &b) {
  int t;
  t = a, a = b, b = t;
}

void gen(int n, ll x, int a, int b, int c, int d, int seq[]) {
  for (int i=1; i<=n; i++) {
    seq[i] = i;
  }
  for (int i=1; i<=n; i++) {
    x = (x*x*a+x*b+c)%d;
    swap(seq[i], seq[x%i+1]);
  }
}

inline int getX(int n, int m) {
  return (n-1)/m+1;
}

inline int getY(int n, int m) {
  return (n-1)%m+1;
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static int seq[maxn*maxm+1], pos[maxn*maxm+1];
  int seed, a, b, c, d, n, m, q;
  scanf("%d %d %d %d %d %d %d %d", &seed, &a, &b, &c, &d, &n, &m, &q);
  gen(n*m, seed, a, b, c, d, seq);

  for (int i=1; i<=q; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    swap(seq[u], seq[v]);
  }

  for (int i=1; i<=n*m; i++) {
    pos[seq[i]] = i;
  }

  static int ans[maxn+maxm+1], maxv[maxm+1], minv[maxm+1];
  for (int i=1; i<=m; i++) {
    minv[i] = n+1;
  }
  for (int i=1; i<=n*m; i++) {
    if (maxv[getY(pos[i], m)]<=getX(pos[i], m) && minv[getY(pos[i], m)]>=getX(pos[i], m)) {
      ans[++ans[0]] = i;
      for (int j=getY(pos[i], m)-1; j>0; j--) {
	minv[j] = min(minv[j], getX(pos[i], m));
      }
      for (int j=getY(pos[i], m)+1; j<=m; j++) {
	maxv[j] = max(maxv[j], getX(pos[i], m));
      }
    }
  }

  for (int i=1; i<=ans[0]; i++) {
    printf("%d ", ans[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
